//
//  ForgetPayPWRetypePasswordController.m
//  HuLaQuan
//
//  Created by hok on 1/23/16.
//  Copyright © 2016 Jianghao. All rights reserved.
//

#import "ForgetPayPWRetypePasswordController.h"

#import "ForgetPayPasswordEngine.h"

//Back To
#import "UserSecurityViewController.h"

@interface ForgetPayPWRetypePasswordController ()

@property (nonatomic, strong) ForgetPayPasswordEngine *forgetPayPasswordEngine;

@end

@implementation ForgetPayPWRetypePasswordController

- (ForgetPayPasswordEngine *)forgetPayPasswordEngine
{
    if (!_forgetPayPasswordEngine) {
        _forgetPayPasswordEngine = [[ForgetPayPasswordEngine alloc] init];
    }
    return _forgetPayPasswordEngine;
}
-(NSString *)finish:(NSString *)pwd{
    NSLog(@"retype %@",self.passwordAndInfos);
    
    //  [self.passwordAndInfos setObject:pwd forKey:@"checkpassword"];
    if ([pwd isEqualToString:self.passwordAndInfos[@"password"]] ){
        [YuNetworkStatusUtilities showProgressMessage:NETWORK_LOADING];
        [self.forgetPayPasswordEngine resetPayPassword:pwd];
    }else{
        [self.view makeToast:kPasswordRetypeNotEqual];
    }
    //[self.navigationController popToRootViewControllerAnimated:YES];
    
    return pwd;
}


#pragma mark - CallBack
- (void)resetPayPasswordFinish:(NSNotification*) notification
{
    [YuNetworkStatusUtilities dismissHUD];
    NSDictionary *messageDic = [notification object];//获取到传递的对象
    if ([messageDic[@"isSuccess"] boolValue]) {
        
        UIAlertController *x = [UIAlertController alertWithTitle:@"提示" andMessage:@"重置支付密码成功" andBlock:^(UIAlertAction *action ) {
            if ([action.title isEqualToString:@"好的"]) {
                [self.navigationController popToRootViewControllerAnimated:YES];
            }
            
        }  type:@"confirm"];
        [self presentViewController:x animated:YES completion:nil];
        
    }else{
        [self showNetWorkError:messageDic[@"message"]];
        
    }
    
}
#pragma mark - Controller Life Cycle
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(resetPayPasswordFinish:) name:@"ResetPayPasswordFinish" object:nil];
    
    
}

- (void)viewWillDisappear:(BOOL)animated
{
    
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"ResetPayPasswordFinish" object:nil];
    
    [super viewWillDisappear:YES];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Navigation Back
- (void)goBackAction
{
    
    UIAlertController *x = [UIAlertController alertWithTitle:@"提示" andMessage:@"是否放弃忘记支付密码操作" andBlock:^(UIAlertAction *action ) {
        if ([action.title isEqualToString:@"好的"]) {
            if ([self.navigationController.viewControllers[1] isKindOfClass:[UserSecurityViewController class]]) {
                [self.navigationController popToViewController:self.navigationController.viewControllers[1] animated:YES];
            }
        }
        
    }  type:@"confirmAndCancel"];
    [self presentViewController:x animated:YES completion:nil];
    
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
